package com.cy.ppj.web.front.order;

import javax.xml.soap.Detail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.Result;
import com.cy.ppj.model.ao.order.OrderScanRecordComfirmAO;
import com.cy.ppj.model.dto.user.UserLoginDTO;
import com.cy.ppj.model.enums.OrderStatus;
import com.cy.ppj.model.query.order.OrderScanRecordQuery;
import com.cy.ppj.model.vo.OrderScanRecordDetailVO;
import com.cy.ppj.model.vo.admin.order.OrderScanRecordVO;
import com.cy.ppj.service.order.OrderService;
import com.cy.ppj.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 订单浏览记录管理
 *
 * @author: tanyilin
 * @create: 2018年9月27日 下午3:32:42
 */
@Slf4j
@RestController
@RequestMapping("/user/order/scan/record")
@Api(tags = "订单浏览记录管理")
public class OrderScanRecordController extends BaseController{

	@Autowired
	private OrderService orderService;
	
	@ApiOperation("前台订单浏览记录列表")
	@GetMapping("/list")
	public PageBean<OrderScanRecordVO> scanRecordList(OrderScanRecordQuery query) {
		UserLoginDTO user = this.getUser();
		query.setUserId(user.getUserId());
		query.setUserType(user.getType());
		PageBean<OrderScanRecordVO> pageBean = orderService.selectOrderScanRecord(query);
		return pageBean;
	}
	
	@ApiOperation("订单浏览记录信息")
	@GetMapping("/detail")
	public Result<OrderScanRecordDetailVO> detail(@ApiParam(value = "订单ID", example = "0", required = true) @RequestParam Long id) {
		OrderScanRecordDetailVO model = orderService.selectOrderScanRecordDetail(id);
		return ok("", model);
	}
	
	@ApiOperation("交单")
	@PostMapping("/do/confirm")
	public Result doConfirm(@Validated OrderScanRecordComfirmAO orderScanRecordComfirmAO, BindingResult bindingResult) {
		this.checkError(bindingResult);
		orderService.doConfirmOrderScanRecord(orderScanRecordComfirmAO);
		return ok();
	}
	
	@ApiOperation("撤销订单")
	@PostMapping("/do/return")
	public Result doReturn(@ApiParam(value = "订单ID", example = "0", required = true) @RequestParam Long orderId) {
		orderService.doConfirmOrReturnOrderScanRecord(orderId, OrderStatus.APPLY_FAIL, 0L);
		return ok();
	}
}
